<template>
  <div class="common-layout">
    <el-container class="contain">
      <el-header>
        <div class="header">
          <div class="left"><img src="../assets/word.jpeg" class="logo" style="width: 50px;height: 50px;border-radius: 50%;" alt="">
          <div class="headtitle">文档资源管理平台</div>
          </div>
          <div class="right">
            <img src="../assets/ceshi.png"  class="logo" style="width: 50px;height: 50px;border-radius: 50%;" alt="">
           
            <el-dropdown>
    <span class="el-dropdown-link">
   {{userinfo.username}}
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item @click.native="routerge()">个人中心</el-dropdown-item>
        <el-dropdown-item @click.native="logout()">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
        :default-active="acrivemenu"
        router
        class="el-menu-vertical-demo"
        @select="handleSelect"
       
      >
      
        <el-menu-item index="/word">
          <el-icon><icon-menu /></el-icon>
          <span>文件管理</span>
        </el-menu-item>
        <el-menu-item index="/user">
          <el-icon><icon-menu /></el-icon>
          <span>用户管理</span>
        </el-menu-item>
        <el-menu-item index="/info">
          <el-icon><icon-menu /></el-icon>
          <span>个人中心</span>
        </el-menu-item>
      </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script setup>
import router from '@/router';
import service from '@/utils/request';
import { onMounted, ref } from 'vue';
const token=ref("")
const userinfo=ref({});
onMounted(()=>{
  if(window.localStorage.getItem("ac")){
    acrivemenu.value=window.localStorage.getItem("ac");
  }else{
    acrivemenu.value="/word"
  }
  if(window.localStorage.getItem("userinfo")){
    token.value=(JSON.parse(window.localStorage.getItem("userinfo"))).token
    getuserinfo()
  }
})
const  getuserinfo=async ()=>{
  const res=await service.get("/api/admin/info",{
    // params:{
    //   token:token.value
    // }
  })
  userinfo.value=res.data.userInfo
  window.localStorage.setItem("user",JSON.stringify(userinfo.value))
  console.log(res)
}
const logout=()=>{
  router.push({
    path:"/"
  })
  window.localStorage.clear()
}
const routerge=()=>{
router.push({
  path:"/info"
})
}
const acrivemenu=ref("/word")
const handleSelect=(e)=>{
  console.log(e)
  acrivemenu.value=e
  window.localStorage.setItem("ac",acrivemenu.value)

}

</script>

<style>
.el-dropdown-link {
color: #fff !important;

}
.el-menu{
  height: 100%;
}
.header{
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background: #174393;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0px 20px !important;
}
.logo{
  margin-right: 10px;
}
.left{
  display: flex;
  align-items: center;
}
.right{
  display: flex;
  align-items: center;
}
.el-header{
padding: 0px !important;
}
.headtitle{

    flex: 1;
    color: #fff;
    cursor: pointer;
    margin-left: 10px;
    font-size: 20px;
    font-weight: 700;

}
.contain{
  width: 100%;
  height: 100%;
}
</style>
